package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(value = "获取一，二，三级分类")
@RequestMapping("/admin/product")
@RestController
public class BaseCategoryController {

    @Autowired
    BaseCategory1Service baseCategory1Service;

    @Autowired
    BaseCategory2Service baseCategory2Service;

    @Autowired
    BaseCategory3Service baseCategory3Service;


    @ApiParam(value = "获取一级分类")
    @GetMapping("/getCategory1")
    public Result getAllcategory1(){
        List<BaseCategory1> list = baseCategory1Service.list();
        return Result.ok(list);
    }

    @ApiParam(value = "根据一级分类id , 获取二级分类")
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id")Long category1Id){
        //按照1级分类查出他下面的所有二级分类
        List<BaseCategory2> list = baseCategory2Service.list(new QueryWrapper<BaseCategory2>().eq("category1_id", category1Id));
        return Result.ok(list);
    }


    @ApiParam(value = "根据二级分类id , 获取三级分类")
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id")Long category2Id){
        //按照2级分类查出他下面的所有三级分类
        List<BaseCategory3> list = baseCategory3Service.list(new QueryWrapper<BaseCategory3>().eq("category2_id",category2Id));
        return Result.ok(list);
    }

}
